# Definition for a binary tree node.
class TreeNode:
  def __init__(self, x):
    self.val = x
    self.left = None
    self.right = None


class Solution:
  def getMirror(self, root: TreeNode) -> TreeNode:
    import copy
    new_root = copy.deepcopy(root)
    qwq = [new_root]
    root_sav = new_root
    while len(qwq) > 0:
      cur_node = qwq.pop(0)
      cur_node.left, cur_node.right = cur_node.right, cur_node.left
      if cur_node.left:
        qwq.append(cur_node.left)
      if cur_node.right:
        qwq.append(cur_node.right)
    return root_sav

  def printTree(self, root: TreeNode) -> TreeNode:
    qwq = [root]
    while len(qwq) > 0:
      cur_node = qwq.pop(0)
      if cur_node:
        print(cur_node.val, end=', ')
      else:
        print('None', end=', ')
        continue
      qwq.append(cur_node.left)
      qwq.append(cur_node.right)

  # B与A进行比较
  def compare(self, A: TreeNode, B: TreeNode) -> bool:
    if not B: return True
    if not A or B.val != A.val: return False
    return self.compare(A.left, B.left) and self.compare(A.right, B.right)

  def isSymmetric(self, root: TreeNode) -> bool:
    if not root: return True
    mirror = self.getMirror(root)
    self.printTree(root)
    print()
    self.printTree(mirror)
    print()
    return self.compare(root, mirror)


def stringToTreeNode(input):
  input = input.strip()
  input = input[1:-1]
  if not input:
    return None

  inputValues = [s.strip() for s in input.split(',')]
  root = TreeNode(int(inputValues[0]))
  nodeQueue = [root]
  front = 0
  index = 1
  while index < len(inputValues):
    node = nodeQueue[front]
    front = front + 1

    item = inputValues[index]
    index = index + 1
    if item != "null":
      leftNumber = int(item)
      node.left = TreeNode(leftNumber)
      nodeQueue.append(node.left)

    if index >= len(inputValues):
      break

    item = inputValues[index]
    index = index + 1
    if item != "null":
      rightNumber = int(item)
      node.right = TreeNode(rightNumber)
      nodeQueue.append(node.right)
  return root


def main():
  import sys
  import io

  def readlines():
    for line in io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8'):
      yield line.strip('\n')

  lines = readlines()
  while True:
    try:
      line = next(lines)
      root = stringToTreeNode(line)

      ret = Solution().isSymmetric(root)

      out = (ret)
      print(out)
    except StopIteration:
      break


'''
STATUS: SOLVED
TRIES:  1
TIME:   84 MS
MEMORY: 14.1 MB
'''
if __name__ == '__main__':
  main()
